/*
    2D FDTD simulator
    Copyright (C) 2019 Emilia Blåsten

    This program is free software: you can redistribute it and/or
    modify it under the terms of the GNU Affero General Public License
    as published by the Free Software Foundation, either version 3 of
    the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public
    License along with this program.  If not, see
    <http://www.gnu.org/licenses/>.
*/
/* material.c: The implementations of the functions that are used
 * to define the ez, hx and hy field update coefficients. Also a
 * function to initialize the parameters used by the other functions. */

#include <math.h>

static int sizeX=-1, sizeY=-1;
static double cdtds=-1, imp0=-1;


void materialInit(int width, int height, double courant, double impedance) {
  sizeX = width;
  sizeY = height;
  cdtds = courant;
  imp0 = impedance;
}


// Coefficients used when updating the ez-field
double ezCe(int mm, int nn, int choice) {
  double value = 1;
  if((choice == 3) && (mm < sizeX/2) && (nn > sizeY/2) && (mm - nn > sizeX*0.45 - sizeY*0.55) ) {
    value= 0.8;//exp(-(pow(mm - sizeX*0.4 - sizeY*0.6,2) + pow(nn - sizeY/2,2)) / 50000);
  }
  return value;
}

double ezCh(int mm, int nn, int choice) {
  return ezCe(mm,nn,choice)*cdtds*imp0;
}


// Coefficients used when updating the hx-field
double hxCe(int mm, int nn, int choice) {
  double value = cdtds / imp0;
  return value;
}


double hxCh(int mm, int nn, int choice) {
  return hxCe(mm,nn,choice)*imp0/cdtds;
}

// Coefficients used when updating the hy-field
double hyCe(int mm, int nn, int choice) {
  return hxCe(mm,nn,choice);
}

double hyCh(int mm, int nn, int choice) {
  return hxCh(mm,nn,choice);
}

